package com.dd.stack.file.pojo.req;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dd.stack.file.pojo.DO.ExcelProductDO;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/5/2 12:17
 * @Description ExcelProductDO查询请求类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(description = "ExcelProduct查询请求类")
public class ExcelProductQueryReq {
    @ApiModelProperty(value = "主键ID（精确匹配）")
    private Long id;
    @ApiModelProperty(value = "商品ID（精确匹配）")
    private Long productId;
    @ApiModelProperty(value = "商品名称（模糊查询）")
    private String productName;
    @ApiModelProperty(value = "价格最小值")
    private Double priceMin;
    @ApiModelProperty(value = "价格最大值")
    private Double priceMax;
    @ApiModelProperty(value = "库存数量最小值")
    private Integer stockMin;
    @ApiModelProperty(value = "库存数量最大值")
    private Integer stockMax;
    @ApiModelProperty(value = "创建时间起始值")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTimeStart;
    @ApiModelProperty(value = "创建时间结束值")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTimeEnd;

    /**
     * 根据查询请求生成 MyBatis-Plus 的 QueryWrapper
     * @return QueryWrapper<ExcelProductDO>
     */
    public QueryWrapper<ExcelProductDO> buildQueryWrapper() {

        QueryWrapper<ExcelProductDO> queryWrapper = new QueryWrapper<>();

        if (this.getId() != null) {
            queryWrapper.eq("id", this.getId());
        }
        if (this.getProductId() != null) {
            queryWrapper.eq("product_id", this.getProductId());
        }
        if (this.getProductName() != null) {
            queryWrapper.like("product_name", this.getProductName());
        }
        if (this.getPriceMin() != null) {
            queryWrapper.ge("price", this.getPriceMin());
        }
        if (this.getPriceMax() != null) {
            queryWrapper.le("price", this.getPriceMax());
        }
        if (this.getStockMin() != null) {
            queryWrapper.ge("stock", this.getStockMin());
        }
        if (this.getStockMax() != null) {
            queryWrapper.le("stock", this.getStockMax());
        }
        if (this.getCreateTimeStart() != null) {
            queryWrapper.ge("create_time", this.getCreateTimeStart());
        }
        if (this.getCreateTimeEnd() != null) {
            queryWrapper.le("create_time", this.getCreateTimeEnd());
        }
        return queryWrapper;
    }
}
